#include <bits/stdc++.h>
// 2025/02/04
// tag: 
// Author: Zhang Muen
using namespace std;

using int64 = int64_t;

#define int long long

class MQueue {
private:
    deque<int> q, pos;

public:
    void push(int x, int i)
    {
        while (!q.empty() && q.back() > x)
            q.pop_back(), pos.pop_back();
        q.push_back(x), pos.push_back(i);
    }
    void pop(int i)
    {
        if (!pos.empty() && pos.front() <= i)
            q.pop_front(), pos.pop_front();
    }
    int get_min()
    {
        return q.front();
    }
    int get_max()
    {
        return q.back();
    }
};

int n, m, luck;

signed main()
{
    cin >> n >> m;
    MQueue q;
    q.push(0, 0);
    int ans = INT_MIN;
    for (int i = 1; i <= n; i++) {
        int l;
        cin >> l;
        luck += l;
        q.pop(i - m - 1);
        ans = max(ans, luck - q.get_min());
        q.push(luck, i);
    }
    cout << ans;
    return 0;
}